package com.itcat.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.itcat.api.mysql.PmsMemberPriceApi;
import com.itcat.mapper.PmsMemberPriceMapper;
import com.itcat.mysql.pojo.PmsMemberPrice;
import org.apache.dubbo.config.annotation.DubboService;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author Jerry Broker
 * @project_name rainbow-mall
 * @create 2022-04-03 23:41
 */
@DubboService
public class PmsMemberPriceApiImpl implements PmsMemberPriceApi {
    @Autowired
    private PmsMemberPriceMapper pmsMemberPriceMapper;

    /**
     * 批量保存商品会员价格设置
     *
     * @param memberPriceList
     */
    @Override
    public void saveList(List<PmsMemberPrice> memberPriceList) {
        int i = pmsMemberPriceMapper.batchInsert(memberPriceList);
    }

    /**
     * 通过商品信息查询PmsMemberPrice
     *
     * @param productId
     * @return
     */
    @Override
    public List<PmsMemberPrice> findByProductId(Long productId) {
        LambdaQueryWrapper<PmsMemberPrice> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(PmsMemberPrice::getProductId, productId);
        List<PmsMemberPrice> pmsMemberPriceList = pmsMemberPriceMapper.selectList(queryWrapper);
        return pmsMemberPriceList;
    }

    /**
     * 更新商品会员价格设置
     *
     * @param memberPriceList
     */
    @Override
    public void updateList(List<PmsMemberPrice> memberPriceList) {
        pmsMemberPriceMapper.batchUpdate(memberPriceList);
    }

    /**
     * 删除响应商品id的数据
     *
     * @param productId
     */
    @Override
    public void deleteByProductId(Long productId) {
        LambdaQueryWrapper<PmsMemberPrice> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(productId != null, PmsMemberPrice::getProductId, productId);
        pmsMemberPriceMapper.delete(queryWrapper);
    }
}
